package appconfig

import (
	"github.com/spf13/viper"
	"log"
)

type AppConfig struct {
	Mysql
	Redis
	QiNuYun
}
type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	DataBase string
}
type Redis struct {
	Host     string
	Port     int
	Password string
}
type QiNuYun struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Url       string
}

var ConfigData AppConfig

func Init() {
	viper.SetConfigFile("../appconfig/config.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic("配置文件读取失败")
	}
	err = viper.Unmarshal(&ConfigData)
	if err != nil {
		panic("配置文件解析失败")
	}
	log.Println("配置文件读取成功", ConfigData)
}
